#include "MouseCursor.h"
#include "GraphicFactory.h"
#include "SimpleMap.h"
namespace Implement
{
	using namespace Core::GameLogic;
	using namespace Graphics;
	using namespace Core::Devices;
	
	MouseCursor::MouseCursor(Core::GameLogic::SimpleMap& map):mMap(map),m_Pos(0,0)
	{
	}
	void MouseCursor::OnMouseEvent(MouseListener::SourceType& t)
	{
		if(t.x>=mMap.GetMapSize().width || t.y>=mMap.GetMapSize().height)
		{
			if(t.x>=mMap.GetMapSize().width)
				t.x=mMap.GetMapSize().width-1;
			if(t.y>=mMap.GetMapSize().height)
				t.y=mMap.GetMapSize().height-1;
			return;
		}
		
		m_Pos.Set(t.x,t.y);
	}
	void MouseCursor::OnKeyboardPressingEvent(KeyboardListener::SourceType& t)
	{
		if(t.keyMap[K_RIGHT])
			m_Pos.Set(m_Pos.x+1,m_Pos.y);
		if(t.keyMap[K_LEFT])
			m_Pos.Set(m_Pos.x-1,m_Pos.y);
		if(t.keyMap[K_UP])
			m_Pos.Set(m_Pos.x,m_Pos.y-1);
		if(t.keyMap[K_DOWN])
			m_Pos.Set(m_Pos.x,m_Pos.y+1);

		if(t.keyMap[K_ESCAPE])
			exit(0);


	}
	void MouseCursor::OnKeyboardUpEvent(KeyboardListener::SourceType& t)
	{

	}
	const Position& MouseCursor::GetPos()
	{
		return m_Pos;
	}
}
